<template>
	<view class="tabs" :style="{'top': top}">
		<view 
			v-for="(item, index) in lists" 
			:key="index" 
			:class="['item', act == index && 'item-act']"
			@click="handleTab(index)"
		>
			<view class="item-border" v-if="border && index < lists.length - 1"></view>
			{{item.title}}
		</view>
	</view>
</template>

<script>
	export default{
		props: {
			lists: Array,
			border: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				act: 0,
				top: '0px'
			}
		},
		mounted() {
			// #ifdef MP-WEIXIN
			const { bottom } = uni.getMenuButtonBoundingClientRect();
			this.top = (bottom + 10) + 'px'
			// #endif
		},
		methods: {
			handleTab(index) {
				this.act = index;
				this.$emit('onChange', index)
			}
		}
	}
</script>

<style scoped>
	.tabs{
		position: fixed;
		left: 0;
		z-index: 10;
		width: 750rpx;
		height: 98rpx;
		background: #fff;
		display: flex;
		flex-direction: row;
		overflow-x: auto;
	}
	.item{
		flex: 1;
		min-width: 150rpx;
		height: 98rpx;
		font-size: 28rpx;
		text-align: center;
		line-height: 98rpx;
		box-sizing: border-box;
		position: relative;
	}
	.item-act{
		color: #3791E9;
		border-bottom: 4rpx solid #3791E9;
	}
	.item-border{
		position: absolute;
		right: 0;
		top: 34rpx;
		content: '';
		width: 1px;
		height: 30rpx;
		background: #E4E4E4;
	}
</style>
